package docker

//安装运行mysql

/*

官方文档地址：https://hub.docker.com/_/mysql


目录：
	1.单机
		1.1下载
		1.2运行
		1.3进入容器
		1.4更改配置

-----------下载----------------

	docker pull mysql

-----------运行----------------
//看官方文档

	//默认的mysql配置在/etc/mysql/my.cnf  /etc/mysql  目录下，有文件夹conf.d  文件 my.cnf my.cnf.fallback
	//自定义mysql配置
	//如果 /my/custom/config-file.cnf 是自定义配置文件的路径和名称，则可以像这样启动 mysql 容器 -v /my/custom:/etc/mysql/conf.d  （请注意，此命令中仅使用自定义配置文件的目录路径）
	//这将启动一个新的容器，其中 MySQL 实例使用来自 /etc/mysql/my.cnf
	//		和 /etc/mysql/conf.d/config-file.cnf 的组合启动设置，后者的设置优先。
	// /etc/mysql/conf.d/config-file.cnf 就是自定义mysql设置



	docker run -it --privileged=true -d  --name mysql -p 3306:3306 \
    -v /home/zydh/docker/etc/mysql/conf:/etc/mysql/conf.d \
	-v /home/zydh/docker/volume/mysql/data:/var/lib/mysql \
	-v /home/zydh/logs/mysql:/var/log/mysql	 \
	-e MYSQL_ROOT_PASSWORD=root \
	mysql  --character-set-server=utf8mb4 --collation-server=utf8mb4_unicode_ci

	or

	docker run -it --privileged=true -d  --name mysql-master -p 3307:3306 \
		-v /home/zydh/docker/lib/mysql/mysql-files:/var/lib/mysql-files/  \
		-v /home/zydh/docker/etc/mysql-master/conf:/etc/mysql \
		-v /home/zydh/docker/volume/mysql-master/data:/var/lib/mysql \
		-v /home/zydh/logs/mysql-master/log:/var/log/mysql	 \
		-e MYSQL_ROOT_PASSWORD=【填上自己的密码】 \
		mysql  --character-set-server=utf8mb4 --collation-server=utf8mb4_unicode_ci



	//注释
	//docker运行 -it 交互模式 --privileged=true 扩大容器的权限，解决挂载目录的权限问题 id后台  --name改名	-p端口映射
	docker run -it --privileged=true  -d  --name mysql-volume -p 9033:3306 \
	// 主机目录：容器目录  配置文件  查看docker-200* 目录1
	-v /home/zydh/docker/lib/mysql/mysql-files:/var/lib/mysql-files/  \
	// 主机目录：容器目录  配置文件
	-v /home/zydh/docker/etc/mysql/conf:/etc/mysql/conf.d \
	// 主机目录：容器目录  数据
	-v /home/zydh/docker/volume/mysql/data:/var/lib/mysql \
	//-e env环境配置，mysql的密码
	-e MYSQL_ROOT_PASSWORD=root \
	// 启动mysql		--字符集utf8mb4       校准集  utf8mb4_unicode_ci
	mysql  --character-set-server=utf8mb4 --collation-server=utf8mb4_unicode_ci


	启动成功后，在本地使用mysql工具链接测试，成功

	看图  images/020docker容器数据卷.png


-----------进入容器----------------

	docker exec -it mysql /bin/bash


	查看my.cnf默认配置
root@f3a605fb2edd:l# cd /etc/mysql
root@f3a605fb2edd:/etc/mysql# cat my.cnf
# Copyright (c) 2017, Oracle and/or its affiliates. All rights reserved.
#
# This program is free software; you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation; version 2 of the License.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program; if not, write to the Free Software
# Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301 USA

#
# The MySQL  Server configuration file.
#
# For explanations see
# http://dev.mysql.com/doc/mysql/en/server-system-variables.html

[mysqld]
pid-file        = /var/run/mysqld/mysqld.pid
socket          = /var/run/mysqld/mysqld.sock
datadir         = /var/lib/mysql
secure-file-priv= NULL

# Custom config should go here
!includedir /etc/mysql/conf.d/
root@f3a605fb2edd:/etc/mysql#


	登录mysql，查看数据库和表
	如果遇到mysql无法登录问题，查看docker-200*-2
			ERROR 1045 (28000): Access denied for user 'root'@'localhost' (using password: YES)


root@VM-4-8-debian:~# docker exec -it mysql /bin/bash
root@f3a605fb2edd:/# mysql -uroot -p【填上自己的密码】
....
Your MySQL connection id is 8
Server version: 8.0.27 MySQL Community Server - GPL
.....
mysql>





-----------更改配置----------------

	在宿主机的/home/zydh/docker/etc/mysql/conf 下建立文件   mysql.cnf

	touch  mysql.cnf

	修改mysql的编码,不过这都在docker run 时直接设置，修改后，重启容器 docker restart mysql[容器名]

	vrm mysql.cnf

[client]
default_character_set=utf8mb4
[mysqld]
server=utf8mb4
character-set-server=utf8mb4
collation-server=utf8mb4_unicode_ci

##设置使用命令跳过输入密码过程,在mysqld下添加，使用完毕后，删除
skip-grant-tables
skip-networking



*/
